//
//  UIButton+category.swift
//  FM
//
//  Created by x on 2017/9/25.
//  Copyright © 2017年 HLB. All rights reserved.
//

import UIKit

extension UIButton {
    
    /// 快速创建一个设置文字属性的按钮
    ///
    /// - Parameters:
    ///   - title: 按钮标题
    ///   - titleColor: 按钮标题颜色
    ///   - fontSize: 按钮标题大小
    ///   - tag: 按钮的tag
    ///   - target: <#target description#>
    ///   - action: <#action description#>
    /// - Returns: <#return value description#>
    class func buttonWith(title:String, titleColor:UIColor, fontSize:CGFloat, tag:Int, target:Any?, action:Selector) -> UIButton {
        let btu = UIButton()
        btu.translatesAutoresizingMaskIntoConstraints = false
        btu.tag = tag
        btu.setTitle(title, for: UIControlState.normal)
        btu.setTitleColor(titleColor, for: UIControlState.normal)
        btu.titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        btu.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        
        return btu
    }
    
    
    /// 创建一个设置图片属性的按钮
    ///
    /// - Parameters:
    ///   - image: <#image description#>
    ///   - hightImage: <#hightImage description#>
    ///   - tag: <#tag description#>
    ///   - target: <#target description#>
    ///   - action: <#action description#>
    /// - Returns: <#return value description#>
    class func buttonWith(image:String, hightImage:String, tag:Int, target:Any?, action:Selector) ->UIButton {
        
        let btu = UIButton()
        btu.translatesAutoresizingMaskIntoConstraints = false
        btu.tag = tag
        btu.setBackgroundImage(UIImage.init(named: image), for: UIControlState.normal)
        btu.setBackgroundImage(UIImage.init(named: hightImage), for: UIControlState.selected)
        btu.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        
        return btu
    }
    
}
